<template>
  <div class='video-play' v-if="visible">
    <div class="box">
      <img src="../img/video_close.png"  class="close" @click="close" alt="">
      <p class="title">{{title}}</p>
      <div class="video">
        <videoPlayer
          autoplay
          class="video-player vjs-custom-skin"
          ref="videoPlayer"
          :options="playerOptions"
          :playsinline="true"
          customEventName="customstatechangedeventname"
        ></videoPlayer>
      </div>
    </div>
  </div>
</template>

<script>
import 'video.js/dist/video-js.css'
import { videoPlayer } from 'vue-video-player'

export default {
  name: 'VideoPaly',
  props: {
    visible: {
      type: Boolean,
      default: () => false
    },
    title: {
      type: String,
      default: () => ''
    }
  },
  components: {
    videoPlayer
  },
  computed: {
    player () {
      return this.$refs.videoPlayer.player
    }
  },
  data () {
    return {
      playerOptions: {
        playbackRates: [0.5, 1.0, 1.5, 2.0], // 可选的播放速度
        autoplay: true, // 如果为true,浏览器准备好时开始回放。
        muted: false, // 默认情况下将会消除任何音频。
        loop: true, // 是否视频一结束就重新开始。
        preload: 'auto', // 建议浏览器在<video>加载元素后是否应该开始下载视频数据。auto浏览器选择最佳行为,立即开始加载视频（如果浏览器支持）
        language: 'zh-CN',
        aspectRatio: '16:9', // 将播放器置于流畅模式，并在计算播放器的动态大小时使用该值。值应该代表一个比例 - 用冒号分隔的两个数字（例如"16:9"或"4:3"）
        fluid: true, // 当true时，Video.js player将拥有流体大小。换句话说，它将按比例缩放以适应其容器。
        sources: [{
          type: 'video/mp4', // 类型
          // require引入
          src: require('./video/video1-1.mp4')
          // src: 'https://cdn.theguardian.tv/webM/2015/07/20/150716YesMen_synd_768k_vp8.webm', // url地址
        }],
        poster: '', // 封面地址
        notSupportedMessage: '此视频暂无法播放，请稍后再试', // 允许覆盖Video.js无法播放媒体源时显示的默认信息。
        controlBar: {
          timeDivider: true, // 当前时间和持续时间的分隔符
          durationDisplay: true, // 显示持续时间
          remainingTimeDisplay: false, // 是否显示剩余时间功能
          fullscreenToggle: true // 是否显示全屏按钮
        }
      }
    }
  },
  created () {

  },
  mounted () {

  },
  watch: {

  },
  methods: {
    close () {
      this.$emit('update:visible', false)
    },
    // listen event
    onPlayerPlay (player) {
      // console.log('player play!', player)
    },
    onPlayerPause (player) {
      // console.log('player pause!', player)
    },
    // ...player event

    // or listen state event
    playerStateChanged (playerCurrentState) {
      // console.log('player current update state', playerCurrentState)
    },

    // player is ready
    playerReadied (player) {
      console.log('the player is readied', player)
      // you can use it to do something...
      // player.[methods]
    }
  }
}
</script>

<style lang="scss" scoped>
.video-play{
    position: fixed;
    left: 0PX;
    right: 0PX;
    top: 0PX;
    bottom: 0PX;
    background: rgba(12, 19, 33, .49);
    .box{
    color: white;
    width: 1088PX;
    height: 762PX;
    background: url('../img/video_box.png') no-repeat;
    background-size: cover;
    position: absolute;
    top: 174PX;
    left: 400PX;
    .title{
      font-size: 32PX;
      width: 643PX;
      height: 76PX;
      text-align: center;
      line-height: 76PX;
      font-weight: bold;
      margin: 43PX auto 0PX;
      background: url('../img/video_title.png') no-repeat center center;
      background-size: cover;
    }
    .video{
      margin: 40PX auto;
      width: 1024PX;
      height: 560PX;
      background: ghostwhite;
    }
  }
  .close{
    cursor: pointer;
    height: 69PX;
    position: absolute;
    right: -25PX;
    top: -25PX;
  }
}
::v-deep{
  .video-js .vjs-volume-level,.video-js .vjs-play-progress{
    background-color: rgba(0, 150, 255, 1);
  }
  .vjs-icon-circle:before, .video-js .vjs-play-progress:before, .video-js .vjs-volume-level:before{
    position: absolute;
    top: -6.5PX;
    content: "";
    width: 18PX;
    height: 18PX;
    background: #0096FF;
    border: 2PX solid #FFFFFF;
    border-radius: 50%;
  }
}
</style>
